<?php $id = getId(); ?>
<form id="f<?php _e($id);?>">
<div class="x-list-title">
	<table width="100%" border="0" height="100%">
	<tr>
	<td align="left">
		<h2>Danh sách hợp đồng</h2>
	</td>
	<td align="right">	
		<div class="x-list-options">
			<?php _e( tpl_search_form(baseUrl()."/Crm/Contract/Search", "#Crm/Contract/Search") );?>						
						
			<div class="x-options-container">
				<a class="x-button">Tạo mới  <span class="x-tri">&#9660;</span></a> 
				<div class="x-options">
					<a class="x-options-item" href="#Crm/Contract/Add">Công ty</a>
					<a class="x-options-item" href="#Crm/Contact/Add">Liên hệ</a>
					<a class="x-options-item" href="#Crm/Opportunity/Add">Cơ hội</a>
					<a class="x-options-item" href="#Crm/Contract/Add">Hợp đồng</a>
				</div>
			</div>

			<div class="x-options-container">
				<a class="x-button">Loại hợp đồng  <span class="x-tri">&#9660;</span></a> 
				<div class="x-options">
					<?php foreach( $this->get('cats') as $k => $a ):?>
					<a class="x-options-item" href="#Crm/Contract?parent_id=<?php _e($a['ID']);?>"><?php _e($a['title']);?></a>
					<?php endforeach;?>
				</div>
			</div>
			
			<div class="x-options-container">
				<a class="x-button">Tác vụ khác  <span class="x-tri">&#9660;</span></a> 
				<div class="x-options">
					<a onclick="module_ajax('<?php _baseUrl();?>/Crm/Contract/Delete','f<?php _e($id);?>',this)"  class="x-options-item x-track">Xóa đã chọn</a>
					<a class="x-options-item" onclick="load_inframe('<?php _ctrUrl($this);?>/Export',{ title:'Xuất file', height:'300px',dataForm: 'form#f<?php _e($id);?>' })">Xuất ra Exel </a>
				</div>
			</div>
		</div>
	</td>
	</tr>
	</table>	
</div>

		<?php 
			$vars = $this->get('vars');
			$rlink = '#Crm/Contract';
		?>
		<table width="100%" cellpadding="0" cellspacing="0" class="x-list" >
			<tr>
				<th width="25" align="center">TT</th>
				<th width="60">
					<?php show_order_link('Mã','code',$rlink,$vars) ;?>
				</th>
				<th>
					<?php show_order_link('Tên hợp đồng','title',$rlink,$vars) ;?>
				</th>
				<th width="120">
					<?php show_order_link('Loại','parent_id',$rlink,$vars) ;?>
				</th>
				<th width="150">
					<?php show_order_link('Công ty','customer_id',$rlink,$vars) ;?>
				</th>
				<th width="90">
					<?php show_order_link('Ngày ký','date_reg',$rlink,$vars) ;?>
				</th>
				<th width="100">
					<?php show_order_link('Giá trị','value',$rlink,$vars) ;?>
				</th>
			
				<th width="25" colspan="2">Tác vụ</th>
				
				<th align="center" width="25">
					<div class="x-check-container">
						<div class="x-check">
						<input type="checkbox" class="x-checkbox x-checkall"/>
						</div>
						<div class="x-check-options">
							<a class="x-check-item check-all">Chọn tất cả</a>
							<a class="x-check-item uncheck-all">Bỏ chọn tất cả</a>
						</div>
					</div>
				</th>
			</tr>
			<?php if( count($this->get('posts')) == 0):?>
			<tr>
			<td class='page' colspan='10'>
				<div class='x-page'>Chưa có bản ghi nào được tạo</div>
			</td></tr>
			<?php else:?>
			<?php foreach( $this->get('posts') as $k => $a ):?>
				<tr>
					<td align="center">
						<?php _e($k+1);?>
					</td>
					<td align="center">
						<?php _e(short_title($a['code'],10));?>						
					</td>
					<td>
						<a href="#Crm/Contract/View?ID=<?php _e($a['ID']);?>">
							<?php _e($a['title']);?></a>
					</td>
					<td>
						<a href="#Crm/Contract?parent_id=<?php _e($a['parent_id']);?>">
							<?php _e($a['parent_title']);?></a>
					</td>
					<td>
						<a href="#Crm/Customer/View?ID=<?php _e($a['customer_id']);?>">
							<?php _e(short_title($a['customer_name'],24));?>
					</td>
					<td align="center">
						<?php _e(show_date(DATE_FORMAT,$a['date_reg']));?>
					</td>
					
					<td align="right">
						<?php _e(show_number($a['value']));?> <?php _e( $a['currency_symbol']);?>
					</td>
					
					<td width="25" align="center">
						<?php if(  $a['created_by_id'] == get_user_id() || $this->hasRole('crm_admin') || $a['care_by_id'] == get_user_id()  ){?>
						<a href="#Crm/Contract/Edit?ID=<?php _e($a['ID']);?>" class="x-edit"></a>
						<?php }else{?>
						<a class="x-noedit"></a>
						<?php }?>
					</td>
					<td width="25" align="center">
						<?php 
							unset($vars['p']);
							$url = 'Crm/Contract'.( count($vars) > 0 ? '?'.to_query_configs($vars,false) : '');
							$url = rawurlencode($url);
						?>
						<?php if(  $a['created_by_id'] == get_user_id() || $this->hasRole('crm_admin') ){?>
						<a onclick="module_delete('<?php _baseUrl()?>/Crm/Contract/Delete?ID[]=<?php _e($a['ID']);?>&url=<?php _e($url)?>')" class="x-delete"></a>
						<?php }else{?>
						<a class="x-nodelete"></a>
						<?php }?>
					</td>
					<td align="center">
						<input name="ID[]" value="<?php _e($a['ID'])?>" type="checkbox" class="x-checkbox x-checkall"/>
					</td>
				</tr>
			<?php endforeach;?>
				<tr>
					<td colspan="10" class="page">
						<div class="x-page">
							<?php $this->e('page');?>
						</div>		
					</td>
				</tr>
			<?php endif;?>
			
		</table>
	</form>
